
/**
 * Created by yangfan on 2016/12/26.
 */
define(['config/appregister',
    'business/services/moreHttpServices',
    "business/services/sendMessage",
    "business/services/filter"],function(app,httpService){
    app.directive("personCenter",function($state,$rootScope){
        return {
            templateUrl:"app/business/services/comComponents/personCenterComp.html",
            scope:{
                type:"=confOnself",
                otherUserId:"=otherId"
            },
            link:function(scope,element,attrs){
                if( !angular.isUndefined($rootScope.userLoginInfo.logged)){
                    scope.logged = $rootScope.userLoginInfo.logged;
                }
                if(scope.type == true){
                    getBasePersonInfoByMine();
                }else {
                    if(angular.isUndefined(scope.otherUserId))
                    return ;
                    if( !angular.isUndefined( $rootScope.userLoginInfo.data.userId) && !angular.isUndefined( scope.otherUserId)){
                        if( scope.otherUserId == $rootScope.userLoginInfo.data.userId){
                                scope.type = true;
                            getBasePersonInfoByMine();
                            checkFollow();
                        }else {
                            getBasePersonInfoByOther();
                        }
                    }else{
                        getBasePersonInfoByOther();
                    }
                }
                function getBasePersonInfoByMine(){
                    var req = {
                        type:"GET",
                        uri:"getBasePersonInfoByMine"
                    };
                    httpService.personServices(req).success(function(response){
                        scope.$apply(function(){
                            scope.person = response.data;
                        })
                    }).error(function(){ })
                }
                function getBasePersonInfoByOther(){
                    var req = {
                        type:"GET",
                        uri:"getBasePersonInfoByOther",
                        data:{
                            otherUserId:scope.otherUserId
                        },
                        reremoveCookie:true
                    };
                    httpService.personServices(req).success(function(response){
                        scope.$apply(function(){
                            scope.other = response.data;
                        })
                    }).error(function(){

                    })
                }

                function checkFollow(){
                     var req = {
                         type:"GET",
                         uri:"checkFollow",
                         data:{
                             followUserId:scope.otherUserId
                         }
                     };
                    httpService.userServices(req).success(function(response){
                        //*** ���� ��̨���ص�response ��һ�� ����ֵ
                        scope.$apply(function(){
                            scope.isFollow = response.data;
                        })
                    }).error(function(){})

                }
                checkFollow();
                function follow(){
                    var req = {
                        type:"POST",
                        uri:"follow",
                        data:{
                            followUserId:scope.otherUserId
                        }
                    };
                    httpService.userServices(req).success(function(response){
                        if(response.code == 0){
                            checkFollow();
                        }
                    }).error(function(){})

                }
                scope.goTo = function(state,params){
                    if(!angular.isUndefined(params)){
                        $state.go(state,params,{resolve:true});
                    }else{
                        $state.go(state);
                    }
                };
                scope.follow = function(){
                    follow()
                };
				//头像跳转
				scope.tomyaccount = function() {
					$state.go("myaccount");
				};

                scope.messageConf ={
                    showSuccessNotice :false,
                    showErrorNotice:false,
                    isShow : false ,
                    content : "",
                    name:'',
                    toUserId:''
                };
                scope.sendMessage = function(){
                    scope.messageConf.isShow = true ;
                    scope.messageConf.name = scope.other.nickname ;
                    scope.messageConf.toUserId = scope.other.userId ;
                }
				

            }
        }
    })
});

